/* Bind all ajax request calls */
$(document).ready(function () {
    if ($(".product-container-carousel").length) {
        // Product carousel
    //    $(".product-container-carousel").each(function () {
    //        var _this = $(this);
    //        _this.wrap("<div class='product-container-carousel-wrapper' data-current='0'></div>");
    //        if (_this.children().length) {
    //            if ($(window).width() - _this.parent().width() < 130) {
    //                _this.parent().addClass("contract");
    //            }
    //            for (var i = 0; i < _this.children().length; i++) {
    //                _this.children().eq(i).css({ top: 0, left: _this.children().eq(i).outerWidth() * i });
    //            }
    //            var child = _this.children().eq(0);
    //            setTimeout(function () {
    //                _this.css("height", child.outerHeight(true));
    //                _this.before("<div class='product-container-carousel-bg'></div><div class='prev'><i class='fa fa-chevron-left'></i></div><div class='next'><i class='fa fa-chevron-right'></i></div>");
    //                _this.parent().find(".product-container-carousel-bg").css("height", child.find("img").height() + 1);
    //                _this.parent().find(".next").css({ "margin-top": _this.parent().find(".product-container-carousel-bg").height() / 2 - 20, "margin-left": _this.width() + 10 });
    //                _this.parent().find(".prev").css({ "margin-top": _this.parent().find(".product-container-carousel-bg").height() / 2 - 20, "margin-left": -50 });
    //            },0);
    //        }
    //    });
    //    $(window).bind("resize scroll", function () {
    //        $(".product-container-carousel").each(function () {
    //            var _this = $(this);
    //            _this.parent().removeClass("contract");
    //            var current = parseInt(_this.parent().attr("data-current"));
    //            if (_this.children().length) {
    //                if ($(window).width() - _this.parent().width() < 130) {
    //                    _this.parent().addClass("contract");
    //                }
    //                for (var i = 0; i < _this.children().length; i++) {
    //                    _this.children().eq(i).css({ top: 0, left: _this.children().eq(i).outerWidth() * (i - current) });
    //                }
    //                var child = _this.children().eq(0);
    //                _this.css("height", child.outerHeight(true) );
    //                _this.parent().find(".product-container-carousel-bg").css("height", child.find("img").height() + 1);
    //                _this.parent().find(".next").css({ "margin-top": _this.parent().find(".product-container-carousel-bg").height() / 2 - 20, "margin-left": _this.width() + 10 });
    //                _this.parent().find(".prev").css({ "margin-top": _this.parent().find(".product-container-carousel-bg").height() / 2 - 20, "margin-left": -50 });
    //            }
    //        });
    //    });
    //    $(".product-container-carousel-wrapper .prev, .product-container-carousel-wrapper .next").live("click", function () {
    //        var carousel = $(this).parent().find(".product-container-carousel");
    //        var children = carousel.children();
    //        if (children.length > 0) {
    //            var visible = Math.floor(carousel.width() / children.eq(0).width());
    //            var current = parseInt($(this).parent().attr("data-current"));
    //            if (children.length > visible) {
    //                var slides = 0;
    //                if ($(this).hasClass("prev")) {
    //                    if (current - visible >= 0) {
    //                        slides = visible;
    //                    } else {
    //                        slides = current;
    //                    }
    //                    current = current - slides;
    //                    $(this).parent().attr("data-current", current);
    //                } else if ($(this).hasClass("next")) {
    //                    if (visible * 2 + current <= children.length) {
    //                        slides = visible;
    //                    } else {
    //                        slides = children.length - current - visible;
    //                    }
    //                    current = current + slides;
    //                    $(this).parent().attr("data-current", current);
    //                }
    //                children.stop().animate({ left: "-=" + children.eq(current).position().left });
    //            }
    //        }
    //    });
        $(".product-container-carousel, .featured-collections .category-navigation").each(function () {
            $(this).find(".product-box .modal").appendTo("body");
            $(this).slick({
                infinite: true,
                slidesToShow: 6,
                slidesToScroll: 6,
                dots: true,
                autoplay: true,
                autoplaySpeed: 6000,
                prevArrow: "<div class='slick-prev'><i class='fa fa-chevron-left'></i></div>",
                nextArrow: "<div class='slick-next'><i class='fa fa-chevron-right'></i></div>",
                responsive: [
                    {
                        breakpoint: 1650,
                        settings: {
                            slidesToShow: 5,
                            slidesToScroll: 5
                        }
                    },
                    {
                        breakpoint: 1440,
                        settings: {
                            slidesToShow: 4,
                            slidesToScroll: 4
                        }
                    },
                    {
                        breakpoint: 1179,
                        settings: {
                            slidesToShow: 3,
                            slidesToScroll: 3
                        }
                    },
                    {
                        breakpoint: 767,
                        settings: {
                            slidesToShow: 2,
                            slidesToScroll: 2,
                        }
                    },
                    {
                        breakpoint: 480,
                        settings: {
                            slidesToShow: 1,
                            slidesToScroll: 1,
                        }
                    },
                ]
            });
        });

    }
    if ($(".recent-viewed-products").length) {
        $(".recent-viewed-products .product-container").slick({
            infinite: true,
                slidesToShow: 14,
                slidesToScroll: 14,
                dots: true,
                prevArrow: "<div class='slick-prev'><i class='fa fa-chevron-left'></i></div>",
                nextArrow: "<div class='slick-next'><i class='fa fa-chevron-right'></i></div>",
                responsive: [
                    {
                        breakpoint: 1650,
                        settings: {
                            slidesToShow: 12,
                            slidesToScroll: 12
                        }
                    },
                    {
                        breakpoint: 1440,
                        settings: {
                            slidesToShow: 10,
                            slidesToScroll: 10
                        }
                    },
                    {
                        breakpoint: 1179,
                        settings: {
                            slidesToShow: 8,
                            slidesToScroll: 8
                        }
                    },
                    {
                        breakpoint: 767,
                        settings: {
                            slidesToShow: 6,
                            slidesToScroll: 6,
                        }
                    },
                    {
                        breakpoint: 480,
                        settings: {
                            slidesToShow: 4,
                            slidesToScroll: 4,
                        }
                    },
                ]
        });
    }
    if ($("#onepage-checkout").length) {
        // one page checkout page
        handleCheckoutPageRequest(null, $(".checkout-main form"), $(".checkout-main-content"));

        $(".checkout-address-select-button").live("click", function (e) {
            $(".alert").remove();
            fadeAnimate($(".checkout-address"), $(".checkout-available-addresses"), $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-billing-address-new-button").live("click", function (e) {
            $(".alert").remove();
            handleCheckoutPageRequest($(this), null, $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-billing-address-select-button").live("click", function (e) {
            $(".alert").remove();
            handleCheckoutPageRequest($(this), null, $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-address-new-button").live("click", function (e) {
            $(".alert").remove();
            $(".render-address-form").empty().html($(".checkout-address-form-hidden .address-new").clone());
            fadeAnimate($(".checkout-address, .checkout-available-addresses"), $(".checkout-address-form"), $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-address-edit-address-button").live("click", function (e) {
            $(".alert").remove();
            $(".render-address-form").empty().html($(".checkout-address-form-hidden .address-edit").clone());
            fadeAnimate($(".checkout-address, .checkout-available-addresses"), $(".checkout-address-form"), $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-available-addresses .back-button").live("click", function (e) {
            $(".alert").remove();
            fadeAnimate($(".checkout-available-addresses"), $(".checkout-address"), $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-address-form .back-button").live("click", function (e) {
            $(".alert").remove();
            if ($(".checkout-address").hasClass("non-saved")) {
                fadeAnimate($(".checkout-address-form"), $(".checkout-available-addresses"), $(".checkout-main-content"));
            } else {
                fadeAnimate($(".checkout-address-form"), $(".checkout-address"), $(".checkout-main-content"));
            }
            e.stopPropagation();
            return false;
        });
        $(".checkout-address-select-address-button").live("click", function (e) {
            handleCheckoutPageRequest($(this), null, $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        
        $(".checkout-address-continue-button").live("click", function (e) {
            handleCheckoutPageRequest($(this), $(this).closest("form"), $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-address-save-button").live("click", function (e) {
            handleCheckoutPageRequest(null, $(this).closest("form"), $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-payment-method-button").live("click", function (e) {
            handleCheckoutPageRequest($(this), $(this).closest("form"), $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-payment-continue-button, .checkout-confirm-continue-button").live("click", function (e) {
            handleCheckoutPageRequest(null, $(this).closest("form"), $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-request-step-button").live("click", function (e) {
            handleCheckoutPageRequest($(this), null, $(".checkout-main-content"));
            e.stopPropagation();
            return false;
        });
        $(".checkout-available-addresses input.address-filter").live("keypress keyup keydown blur", function () {
            var val = $(this).val().toLowerCase();
            if (val.replace(/\s+/g, '') == "") {
                $(".address-select-list .address-select-item").removeClass("hide");
            } else {
                $(".checkout-available-addresses .address-item").each(function () {
                    var text = $(this).find(".address-render-content").text().toLowerCase();
                    if (text.indexOf(val) > 0) {
                        $(this).removeClass("hide");
                    } else {
                        $(this).addClass("hide");
                    }
                });
                //var matchList = val.split(/,?\s+/);
                //if (matchList.length == 1) {
                //    $(".checkout-available-addresses .address-item").each(function () {
                //        var text = $(this).find(".address-render-content").text().toLowerCase();
                //        if (text.indexOf(matchList[0].toLowerCase()) > 0) {
                //            $(this).removeClass("hide");
                //        } else {
                //            $(this).addClass("hide");
                //        }
                //    });
                //} else {
                //    $(".checkout-available-addresses .address-item").removeClass("hide");
                //    for (var match in matchList) {
                //        $(".checkout-available-addresses .address-item").each(function () {
                //            var text = $(this).find(".address-render-content").text().toLowerCase();
                //            if (!(text.indexOf(match.toLowerCase()) > 0)) {
                //                $(this).addClass("hide");
                //            }
                //        });
                //    }
                //}
            }
        });
    }
    $("button").live("click", function (e) {
        e.preventDefault();
        e.stopPropagation();
        return false;
    });
    // Open box item load request
    $(".product-load-openbox-items").live("click", function (e) {
        handleCheckoutPageRequest($(this), null, $(this).closest("form").next(".open-box-items"));
        $("html, body").stop().animate({ scrollTop: $(this).closest(".product-variant-wrapper").find(".open-box-items").offset().top });
        e.stopPropagation();
        return false;
    });

    // Shopping cart edit actions
    $(".product-quantity-editor input").each(function () {
        checkQuantityEditor($(this));
    });
    $(".product-quantity-editor .plus").live("click", function () {
        if (!$(this).hasClass("disabled")) {
            var elem = $(this).parent().children("input");
            if (elem.length) {
                var max = 100;
                if (parseInt(elem.attr("data-max")) > 0) {
                    max = parseInt(elem.attr("data-max"));
                }
                var value = parseInt(elem.val());
                if (!isNaN(value) && value >= 0 && value < max) {
                    elem.val(value + 1);
                }
                checkQuantityEditor(elem);
                $(this).closest("tr").find(".cart-item-update-button").show();
            }
        }
    });
    $(".product-quantity-editor .minus").live("click", function () {
        if (!$(this).hasClass("disabled")) {
            var elem = $(this).parent().children("input");
            if (elem.length) {
                var min = 1;
                if (parseInt(elem.attr("data-min")) > 0) {
                    min = parseInt(elem.attr("data-min"));
                }
                var value = parseInt(elem.val());
                if (!isNaN(value) && value >= 0 && value > min) {
                    elem.val(value - 1);
                }
                checkQuantityEditor(elem);
                $(this).closest("tr").find(".cart-item-update-button").show();
            }
        }
    });
    $(".product-quantity-editor input").live("change", function () {
        if (!$(this).closest("tr").hasClass("disabled")) {
            //if (checkValidCartQuantity($(this))) {
            //    $(this).attr("data-value", $(this).val());
            //    handleCheckoutPageRequest($(this), null, null, true);
            //}
            $(this).closest("tr").find(".cart-item-update-button").show();
        }
    });
    $(".cart-item-update-button input").live("click", function () {
        $(this).closest(".cart-item-update-button").hide();
        $(this).closest("tr").find(".product-quantity-editor").hide();
        var inputElem = $(this).closest("tr").find(".product-quantity-editor input");
        if (checkValidCartQuantity(inputElem)) {
            $(this).closest("tr").find(".cart-item-loading").show();
            inputElem.attr("data-value", inputElem.val());
            handleCheckoutPageRequest(inputElem, null, null, true);
        }
    });
    $(".cart-store-items-remove").live("click", function (e) {
        if (!$(this).closest("tr").hasClass("disabled")) {
            handleCheckoutPageRequest($(this), null, null, true);
            e.stopPropagation();
            return false;
        }
    });

});

function checkQuantityEditor(elem) {
    var minusControl = elem.parent().children(".minus");
    var plusControl = elem.parent().children(".plus");
    var max = 100;
    var min = 1;
    if (parseInt(elem.attr("data-min")) > 0) {
        min = parseInt(elem.attr("data-min"));
    }
    if (parseInt(elem.attr("data-max")) > 0) {
        max = parseInt(elem.attr("data-max"));
    }
    minusControl.removeClass("disabled");
    plusControl.removeClass("disabled");
    var value = parseInt(elem.val());
    if (!isNaN(value) && value > 0) {
        if (value >= max && plusControl.length) {
            plusControl.addClass("disabled");
        }
        if (value <= min && minusControl.length) {
            minusControl.addClass("disabled");
        }
    } else {}
}

function editcartitem(elem, type, qty) {
    var itemrow = elem.closest(".cart-store-item"),
    itemstore = elem.closest(".cart-store-wrapper"),
    itemstoretotal = elem.closest(".cart-store").parent().find(".total-info"),
    sciid = elem.closest(".cart-store-item").attr("data-sci"),
    storeid = elem.closest(".cart-store").attr("data-storeid"),
    editurl;
    if (type == "remove") {
        editurl = $("#cart-remove-item").val();
    } else {
        editurl = $("#cart-edit-item").val();
    }
    $.ajax({
        url: editurl,
        data: { sciId: sciid, storeId: storeid, itemQuantity: qty, path: window.location.pathname },
        type: "POST"
    }).always(function () {
        $(".cart-item-loading-" + sciid).remove();
    }).done(function (response) {
        if (typeof (response.redirect) != 'undefined') {
            window.location.href = response.redirect;
        } else if (response.removeStore == true && $(".cart-stores").length) {
            itemstore.remove();
        } else {
            if (response.success == true) {
                if (typeof (response.sciHtml) != 'undefined') {
                    itemrow.replaceWith(response.sciHtml);
                } else {
                    itemrow.remove();
                }
            }
            if (typeof (response.totalHtml) != 'undefined') {
                itemstoretotal.replaceWith(response.totalHtml);
            }
        }
    });
}

function checkValidCartQuantity(elem) {
    var orignumber = parseInt(elem.attr("data-orig"));
    var maxnumber = parseInt(elem.attr("data-max"));
    var newnumber = parseInt(elem.val());
    // Validates number
    if (newnumber == "" || isNaN(newnumber) || newnumber <= 0 || newnumber == orignumber ||(!isNaN(maxnumber) && newnumber >= maxnumber)) {
        elem.val(orignumber);
        return false;
    }
    return true;
}

function slideAnimate(curslide, nextslide, direction) {
    var dest = 0;
    if (direction == "left") {
        dest = "-100%";
        nextslide.css({
            position: "absolute",
            left: "100%",
            top: 0,
            height: "auto"
        });
    } else if (direction == "right") {
        dest = "100%";
        nextslide.css({
            position: "absolute",
            left: "-100%",
            top: 0,
            height: "auto"
        });
    }
    curslide.stop().animate({
        left: dest
    }, 200);
    nextslide.stop().animate({
        left: 0
    }, 200, function () {
        curslide.css({ position: "absolute", height: 0 });
        nextslide.css("position", "relative");
    });
}

function fadeAnimate(curslide, nextslide, wrapper) {
    if ($("body").scrollTop() > $("#main").offset().top) {
        $("html, body").stop().animate({
            scrollTop: $("#main").offset().top
        }, 200);
    }
    wrapper.children().stop().animate({
        opacity: 0
    }, 200, function () {
        wrapper.css({ height: wrapper.height() });
        curslide.hide();
        nextslide.show();
        wrapper.stop().animate({ height: wrapper.children().outerHeight(true) + 20 }, 200, function () {
            wrapper.children().stop().animate({
                opacity: 1
            }, 200);
            wrapper.css("height", "auto");
        });
    });
}

function submitCheckoutCartRequest() {
    if ($(".checkout-cart-request form").length) {
        $.ajax({
            url: $(".checkout-cart-request form").attr("action"),
            type: "POST",
            dataType: "JSON"
        }).done(function (data) {
            if (data.products) {
                $(".checkout-cart-products .products-wrapper-inner").html(data.products);
            }
            if (data.summary) {
                $(".checkout-cart-summary .cart-order-total").html(data.summary);
            }
        });
    }
}

function handleCheckoutPageRequest(elem, form, datawrapper, isCartAction) {
    var url = "";
    var type = "POST";
    var datavalues = [];
    if (form != null) {
        url = form.attr("action");
        type = form.attr("method");
        datavalues = form.serializeArray();
    } else {
        url = elem.attr("data-url");
    }
    if (elem != null && elem.attr("data-name") != "" && elem.attr("data-value") != "") {
        datavalues.push({ name: elem.attr("data-name"), value: elem.attr("data-value") });
    }
    if (elem != null && elem.attr("data-name2") != "" && elem.attr("data-value2") != "") {
        datavalues.push({ name: elem.attr("data-name2"), value: elem.attr("data-value2") });
    }
    if (elem != null && elem.attr("data-name3") != "" && elem.attr("data-value3") != "") {
        datavalues.push({ name: elem.attr("data-name3"), value: elem.attr("data-value3") });
    }
    if (elem != null && elem.attr("data-name4") != "" && elem.attr("data-value4") != "") {
        datavalues.push({ name: elem.attr("data-name4"), value: elem.attr("data-value4") });
    }
    if (url != "" && type != "") {
        if (isCartAction == true) {
            elem.closest("tr").addClass("disabled").find("input").attr("disabled", "disabled");
            checkoutPageRequest(url, type, datavalues, elem, form, datawrapper, isCartAction);
        } else {
            $(".alert").remove();
            $(".checkout-loading").fadeIn(200);
            if (typeof datawrapper != "undefined" && datawrapper.hasClass("checkout-main-content")) {
                datawrapper.children().stop().animate({ opacity: 0 }, 200, function () {
                    checkoutPageRequest(url, type, datavalues, elem, form, datawrapper, isCartAction);
                    datawrapper.stop().animate({ height: 0 }, 200);
                });
            } else {
                checkoutPageRequest(url, type, datavalues, elem, form, datawrapper, isCartAction);
            }
        }
        
    } else {
        if (isCartAction == true) {
        } else {
            datawrapper.children().show();
            showCheckoutErrorMessage($("#opc-message-error-formerror").val(), datawrapper);
        }
    }
}

function checkoutPageRequest(url, type, datavalues, elem, form, datawrapper, isCartAction) {
    if ($("body").scrollTop() > $("#main").offset().top) {
        $("html, body").stop().animate({
            scrollTop: $("#main").offset().top
        }, 200);
    }
    $.ajax({
        url: url,
        type: type,
        dataType: "JSON",
        data: datavalues
    }).done(function (data) {
        if (isCartAction == true) {
            elem.closest("tr").addClass("disabled").find("input").attr("disabled", "disabled");
            if (data.cart) {
                if (data.sciId && $(".cart-order-summary tr[data-sci=" + data.sciId + "]").length) {
                    var cartPlaceHolder = $("<div></div>").html(data.cart);
                    $(".cart-order-summary tr[data-sci=" + data.sciId + "]").replaceWith(cartPlaceHolder.find("tr[data-sci=" + data.sciId + "]"));
                } else {
                    $(".cart-order-summary").html(data.cart);
                }
            }
            if (data.orderTotal) {
                $(".cart-order-total").html(data.orderTotal);
            }
            if (data.flyoutCart) {
                $(".flyout-cart .cart-wrapper").replaceWith(data.flyoutCart);
            }
            if (data.qty) {
                if (data.qty > 0) {
                    $(".header-cart .cart-quantity").text(data.qty).show();
                } else {
                    $(".header-cart .cart-quantity").text("").hide();
                }
            }
            if (data.message) {
                if (data.success == true) {
                    AjaxCart.displayPopupNotification("", data.message, "success");
                }
                else {
                    AjaxCart.displayPopupNotification("", data.message, "error");
                }
            }
        } else {
            if (data.success != "" && data.success == true && $(".checkout-cart-request form").length) {
                submitCheckoutCartRequest();
                $(".checkout-cart-summary, .checkout-cart-products").addClass("loading");
                $(".checkout-main").removeClass("fullwidth");
            } else {
                $(".checkout-cart-summary, .checkout-cart-products").removeClass("loading shown");
                $(".checkout-main").addClass("fullwidth");
            }
            if (typeof data.html != "undefined" && data.html != "") {
                datawrapper.html(data.html);
            }
            if (datawrapper.hasClass("checkout-main-content")) {
                datawrapper.css({ height: 0 }).children().css({ opacity: 0 });
                datawrapper.stop().animate({ height: datawrapper.children().outerHeight(true) + 20 }, 200, function () {
                    datawrapper.css("height", "auto");
                    datawrapper.children().stop().animate({ opacity: 1 }, 200);
                });
            }
            if (data.messages) {
                datawrapper.prepend(data.messages);
            }
            if (typeof data.title != "undefined" && data.title != "") {
                $(".checkout-title").html("- " + data.title);
            } else {
                $(".checkout-title").html("");
            }

            if (typeof data.step != "undefined") {
                if (parseInt(data.step) == 6) {
                    // Order complete
                    $(".checkout-steps").css("overflow", "hidden").stop().animate({height: 0}, 200);
                } else if (parseInt(data.step) >= 0) {
                    setTimeout(showCheckoutStep(data.step), 500);
                }
            }
            if (typeof data.enable != "undefined") {
                setTimeout(function () {
                    for (var item in data.enable) {
                        if (!$(".checkout-step-" + data.enable[item]).hasClass("enabled")) {
                            $(".checkout-step-" + data.enable[item]).addClass("enabled");
                        }
                    }
                }, 500);
            }
            if (typeof data.disable != "undefined") {
                for (var item in data.disable) {
                    setTimeout(function () {
                        for (var item in data.disable) {
                            if ($(".checkout-step-" + data.disable[item]).hasClass("enabled")) {
                                $(".checkout-step-" + data.disable[item]).removeClass("enabled");
                            }
                        }
                    }, 500);
                }
            }
            if (typeof data.complete != "undefined" && data.complete == true) {
                $(".edit-shopping-cart-button").remove();
            }
            if (typeof data.url != "undefined" && data.url != "") {
                if (data.url != window.location.pathname);
                {
                    history.replaceState({}, $("title").text(), data.url);
                }
            }
        }
    }).error(function () {
        if (isCartAction == true) {
        } else {
            datawrapper.children().show();
            showCheckoutErrorMessage($("#opc-message-error-servererror").val(), datawrapper);
        }
    }).always(function () {
        if (isCartAction == true) {
            elem.closest("tr").removeClass("disabled").find("input").attr("disabled", false);
            elem.closest("tr").find(".cart-item-loading").hide();
            elem.closest("tr").find(".product-quantity-editor").show();
        } else {
            $(".checkout-loading").fadeOut(200);
        }
    });
}

function showCheckoutStep(step) {
    step = parseInt(step);
    var percent = $("#opc-step-percent-" + step).val();
    $(".checkout-steps-progress .progress-bar").stop().animate({ width: percent }, 500);
    $(".checkout-step").css("border-radius", "5px").stop().animate({
        height: 150
    });
    $(".checkout-step-" + step).css("border-radius", 0).stop().animate({
        height: 175
    });
}
function showCheckoutErrorMessage(msg, datawrapper) {
    $(".alert").remove();
    var msgstring = "<div class='alert alert-danger alert-dismissible' role='alert'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button><ul><li>" + msg + "</li></ul></div>";
    datawrapper.prepend(msgstring);
}
function showCheckoutSuccessMessage(msg) {
    $(".alert").remove();
    var msgstring = "<div class='alert alert-success alert-dismissible' role='alert'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button><ul><li>" + msg + "</li></ul></div>";
    datawrapper.prepend(msgstring);
}